﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZhwangTool
{
    public class MyFileInfo : INotifyPropertyChanged
    {
        long size = 0;
        string name;
        uint crc32 = 0;
        string md5;
        string hash;
        string groupTag;
        bool toShow;



        public string ErrMessage { get; set; }

        public MyFileInfo(string nameStr)
        {
            name = nameStr;

            groupTag = "GroupTag";

            toShow = true;
        }
        //构造函数
        //从源头上控制myFileInfo对象文件是存在的
        string givenFolder;

        public MyFileInfo(string nameStr, string foderStr) : this(nameStr)
        {
            //name = nameStr;

            //groupTag = "GroupTag";

            givenFolder = foderStr;

            toShow = true;

        }
        public override string ToString()
        {
            //
            //item.Remove(0, textBox1.Text.Length
            return Name.Remove(0, GivenFolder.Length);
        }

        public string GetDirectoryName()
        {
            FileInfo fileInfo = new FileInfo(name);

            return fileInfo.DirectoryName;

        }

        string shortName;
        bool sign;
        int tag;

        public string Md5 { get => md5; set => md5 = value; }
        public string Hash { get => hash; set => hash = value; }
        public uint Crc32 { get => crc32; set => crc32 = value; }
        public long Size { get => size; set => size = value; }
        public string GivenFolder { get => givenFolder; set => givenFolder = value; }
        public string Name { get => name; }
        public string ShortName
        {

            get => Name.Substring(GivenFolder.Length);

            set => shortName = value;

        }

        public bool Sign
        {
            get { return sign; }
            set
            {
                sign = value;
                NotifyPropertyChanged("Sign");
            }
        }

        public DateTime LastWriteTime
        {
            get
            {
                return new FileInfo(Name).LastWriteTime;

            }
        }


        public DateTime CreationTime
        {
            get
            {
                return new FileInfo(Name).CreationTime;

            }
        }

        public string Extension
        {
            get
            {
                return new FileInfo(Name).Extension;

            }
        }


        public int Tag { get => tag; set => tag = value; }

        public string SizeInMb
        {
            get
            {
                return (Size / 1024.0 / 1024.0).ToString("#0.000");

            }
        }

        public string SizeInMbFromFileLength
        {
            get
            {
                return (new FileInfo(Name).Length/1024.0/1024.0).ToString("F3");
                
            }
        }



        public string GroupTag { get => groupTag; }
        public bool ToShow { get => toShow; set => toShow = value; }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        
    }

    public class BaseMyFileInfo : INotifyPropertyChanged
    {

        long size = 0;
        string sizeInKb = string.Empty;

        string name;

        public BaseMyFileInfo(string givenName)
        {
            Name = givenName;

        }

        public string Name { get => name; set => name = value; }

        public long Size { get => size; set => size = value; }

        public string SizeInKb
        {
            get => (Size / 1024).ToString("#0.000");
            
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }


    }
}
